import { Column, Entity, Index, Tree, TreeChildren, TreeParent } from 'typeorm';
import { CommonEntity, CommonStatus } from '~/common/entity/common.entity';

@Entity({ name: 'ah_catalog' })
@Index(['id'])
@Tree('materialized-path')
export class CatalogEntity extends CommonEntity {
	@Column({ type: 'varchar', length: 50, comment: '目录名称' })
	name: string;

	@Column({ type: 'varchar', length: 100, comment: '目录编码', nullable: true })
	code: string;

	@Column({ type: 'varchar', length: 200, nullable: true, comment: '目录描述' })
	description: string;

	@Column({ type: 'int', default: 0, comment: '排序值', name: 'sort_order' })
	sortOrder: number;

	@Column({ type: 'tinyint', width: 1, default: CommonStatus.YES, comment: '是否启用', name: 'is_active' })
	isActive: CommonStatus;

	@TreeParent()
	parent?: CatalogEntity;

	@TreeChildren({ cascade: true })
	children: CatalogEntity[];

	// 推送开始时间、推送结束时间 YYYY-MM-DD HH:mm:ss
	@Column({ type: 'datetime', nullable: true, comment: '推送开始时间', name: 'push_start_time' })
	pushStartTime: Date;

	@Column({ type: 'datetime', nullable: true, comment: '推送结束时间', name: 'push_end_time' })
	pushEndTime: Date;

	// 关联的分类ID
	@Column({ type: 'int', nullable: true, comment: '关联的分类ID', name: 'category_id' })
	categoryId: number;
}